package com.jerkin.annotations.aspect;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.core.annotation.Order;

/**
 * @version V1.0
 * @ClassName: ProxyTestAspect
 * @Description:
 * @author: huhongzhi
 * @date: 2021/1/10 23:45
 */
@Slf4j
@Aspect
@Order(-1000000000)
@Configuration
@EnableAspectJAutoProxy
public class ProxyTestAspect {

    @Pointcut("@annotation(com.jerkin.annotations.ProxyTest)")
    public void handleProxy() {
    }

    @Around("handleProxy()")
    public Object dohandleTrace(ProceedingJoinPoint pjp) throws Throwable {
//        log.info("执行的代理对象"+this);
        log.info("dohandleTrace方法开始");
        //先初始化一下traceId
        Object result = null;
        try {
            result = pjp.proceed();
            log.info("dohandleTrace方法结束");
        } catch (Throwable e) {
            throw e;
        } finally {
            log.info("dohandleTrace方法执行了代理的finally");
        }
        return result;
    }
}
